package leetcode.easy;

import leetcode.base.TreeNode;

import java.util.Deque;

/**
 * ClassName: $534_DiameterOfBinaryTree
 * Description:
 * date: 2021-11-17 22:31
 *
 * @author liyifan
 */
public class $534_DiameterOfBinaryTree {

    private int max = Integer.MIN_VALUE;

    public int diameterOfBinaryTree(TreeNode root) {
        depth(root);
        return max;
    }

    public int depth(TreeNode root) {
        if (root == null)
            return 0 ;

        int left = depth(root.left);
        int right = depth(root.right);
        max = Math.max(max, left + right);
        return Math.max(left, right) + 1;
    }
}
